#  -*- coding:utf-8 -*-
import sys
import codecs

if sys.stdout.encoding != 'UTF-8':
    sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
if sys.stderr.encoding != 'UTF-8':
    sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict')

sys.path.append("../")
sys.path.append("/usr/lib/python3/dist-packages")
sys.path.append("/usr/local/lib/python3.5/dist-packages")
sys.path.append('/Users/xuchaosheng/anaconda3/lib/python3.6/site-packages')

from flask import request, jsonify, send_from_directory, abort
from bson.objectid import ObjectId
from gevent.wsgi import WSGIServer
from flask import request, url_for
from flask import render_template
from flask import Flask, jsonify
from flask import make_response
from gevent import monkey
from config import *
from Cache import *
from User import *
from utils import *

import jieba.posseg as pseg
import pandas as pd
import csv, codecs
import datetime
import pymongo
import difflib
import difflib
import pprint
import socket
import time
import jieba
import os
import json
import sys
import re

# 缓存对象
cache = Cache()

monkey.patch_all()

app = Flask(__name__)

# jd格式清理
jfc = JD_FORMAT_CLEAR()


@app.route('/knx/job_query.do', methods = ['GET'])
def job_search_demo():
    PositionName = request.args.get('PositionName', '').strip()
    PageIndex = int(request.args.get('PageIndex', '0').strip())
    PageSize = int(request.args.get('PageSize', '10').strip())
    BeginPay = int(request.args.get('BeginPay', '6000').strip())
    EndPay = int(request.args.get('EndPay', '30000').strip())
    Industry = request.args.get('Industry', '').strip()
    UserKey = request.args.get('UserKey', '').strip()
    UserID = request.args.get('UserID', '').strip()
    Title = request.args.get('Title', '').strip()
    Area = request.args.get('Area', '').strip()
    st = request.args.get('st', '1').strip()

    Title = Title if PositionName == '' else PositionName

    # 记录用户查询操作日志
    user = User(UserID, UserKey)
    user.add_job_queried(Title)

    if Title:
        if st == '0':
            data, total = company_search(Title, Area, PageIndex, PageSize, BeginPay, EndPay, Industry)
        else:
            data, total = semantics_search(Title, Area, PageIndex, PageSize, BeginPay, EndPay, Industry)
    else:
        data, total = default_search(Area, PageIndex, PageSize, BeginPay, EndPay, Industry, UserID, UserKey)

    for job in data:
        job['score'] = user.matching_degree(job['name'])
        job['description'] = ''

        id = job['id'] if 'id' in job else str(job['_id'])
        job['id'] = id

        if UserID != '0':
            job['isCollected'] = user.is_job_collected(job['platform'], id)
            job['isDelivered'] = user.is_job_delivered(job['platform'], id)
            job['totalCollection'] = collection_number(job['platform'], id)

        append_logo_url(job)

        # if '有限公司' in job['company']:
        #     job['company'] = job['company'][:job['company'].find('有限公司')]

        job['company'] = job['company'].replace('拉勾未认证企业', '').strip()

        if '_id' in job:
            del job['_id']

    resp = {
        'success': True,
        'data': data,
        'total': total
    }

    response = make_response(jsonify(resp))
    response.headers['Access-Control-Allow-Origin'] = '*'

    return response


# jd详情
@app.route('/knx/job_detail.do', methods = ['GET'])
def job_detail():
    platform = request.args.get('platform', '').strip()
    id = request.args.get('id', '').strip()

    UserKey = request.args.get('UserKey', '').strip()
    UserID = request.args.get('UserID', '').strip()

    # 记录用户查询操作日志
    user = User(UserID, UserKey)

    user.add_job_viewed(platform, id)

    if len(platform) == 0 or len(id) == 0:
        return json.dumps({
            'success': False,
            'msg': '请同时指定platform和id'
        })

    if platform not in posts_map:
        return json.dumps({
            'success': False,
            'msg': '请指定正确的platform'
        })

    # 从数据库中寻找到对应的jd
    item = posts_map[platform].find_one({'_id': ObjectId(id)}, {'_id': 0})

    item['description'] = jfc(item['description'])

    # 获取企业信息介绍
    if corps_map[platform].find_one({'name': re.compile(item['company'])}):
        item['comp_desc'] = corps_map[platform].find_one({'name': re.compile(item['company'])})['description']

    if UserID != '0':
        item['isDelivered'] = user.is_job_delivered(platform, id)
        item['isCollected'] = user.is_job_collected(platform, id)
        item['score'] = user.matching_degree(item['name'])

    if '有限公司' in item['company']:
        item['company'] = item['company'][:item['company'].find('有限公司')]

    append_logo_url(item)

    data = {
        'success': True,
        'data': item
    }

    response = make_response(jsonify(data))
    response.headers['Access-Control-Allow-Origin'] = '*'

    return response


# 用户简历数据
@app.route('/knx/user_resume.do', methods = ['POST'])
def user_resume():
    response = make_response(jsonify({'success': True}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    data = json.loads(request.form.get('JsonData'))

    UserKey = data['user']['UserKey']
    UserID = data['user']['UserID']

    pprint.pprint(data['data'])

    User(UserID, UserKey).set_user_resume(data['data'])

    return response


# 用户测评数据
@app.route('/knx/user_evaluation.do', methods = ['POST'])
def user_evaluation():
    data = json.loads(request.form.get('JsonData'))

    UserKey = data['user']['UserKey']
    UserID = data['user']['UserID']

    evaluation = data['data']

    User(UserID, UserKey).set_user_evaluation(evaluation)

    response = make_response(jsonify({'success': True}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    return response


# 用户标签选择数据
@app.route('/knx/user_labels.do', methods = ['POST'])
def user_labels():
    response = make_response(jsonify({'success': True}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    data = json.loads(request.form.get('JsonData'))

    UserKey = data['user']['UserKey']
    UserID = data['user']['UserID']

    labels = data['data']

    User(UserID, UserKey).set_labels_selected(labels)

    return response


# 用户职位收藏数据
@app.route('/knx/user_job_collect.do', methods = ['POST'])
def user_job_collect():
    data = parse_form_data(request.form)

    UserKey = data['user']['UserKey']
    UserID = data['user']['UserID']

    if not 'platform' in data['data'] or not 'id' in data['data'] or not 'type' in data['data']:
        response = make_response(jsonify({'success': False}))
        response.headers['Access-Control-Allow-Origin'] = '*'

        return response

    response = make_response(jsonify({'success': True}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    user = User(UserID, UserKey)
    user.add_job_collected(data['data']['platform'], data['data']['id'], data['data']['type'])

    return response


# 用户职位收藏数据（用于后端传递）
@app.route('/knx/user_job_collect_new.do', methods = ['POST'])
def user_job_collect_new():
    # data = parse_form_data(request.form)
    data = json.loads(request.form.get('JsonData'))

    UserKey = data['user']['UserKey']
    UserID = data['user']['UserID']

    if not 'platform' in data['data'] or not 'id' in data['data'] or not 'type' in data['data']:
        response = make_response(jsonify({'success': False}))
        response.headers['Access-Control-Allow-Origin'] = '*'

        return response

    response = make_response(jsonify({'success': True}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    user = User(UserID, UserKey)
    user.add_job_collected(data['data']['platform'], data['data']['id'], data['data']['type'])

    return response


# 用户职位投递数据
@app.route('/knx/user_job_delivery.do', methods = ['POST'])
def user_job_delivery():
    response = make_response(jsonify({'success': True}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    data = parse_form_data(request.form)

    UserKey = data['user']['UserKey']
    UserID = data['user']['UserID']

    # 记录用户查询操作日志
    User(UserID, UserKey).add_job_delivered(data['data']['platform'], data['data']['id'])

    return response


# 用户职位投递数据（用于后端传递）
@app.route('/knx/user_job_delivery_new.do', methods = ['POST'])
def user_job_delivery_new():
    response = make_response(jsonify({'success': True}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    # data = parse_form_data(request.form)
    data = json.loads(request.form.get('JsonData'))

    UserKey = data['user']['UserKey']
    UserID = data['user']['UserID']

    # 记录用户查询操作日志
    User(UserID, UserKey).add_job_delivered(data['data']['platform'], data['data']['id'])

    return response


# 用户收藏的职位列表
@app.route('/knx/jobs_collected_by_user.do', methods = ['GET'])
def jobs_collected_by_user():
    UserKey = request.args.get('UserKey', '')
    UserID = request.args.get('UserID', '')

    user = User(UserID, UserKey)

    if user:
        response = make_response(jsonify({'success': True, 'data': user.get_collected_jobs()}))
        response.headers['Access-Control-Allow-Origin'] = '*'
    else:
        response = make_response(jsonify({'success': False, 'msg': 'is not a valid user'}))
        response.headers['Access-Control-Allow-Origin'] = '*'

    return response


# 用户投递的职位列表
@app.route('/knx/jobs_delivered_by_user.do', methods = ['GET'])
def jobs_delivered_by_user():
    UserKey = request.args.get('UserKey', '')
    UserID = request.args.get('UserID', '')

    user = User(UserID, UserKey)

    if user:
        response = make_response(jsonify({'success': True, 'data': user.get_delivered_jobs()}))
        response.headers['Access-Control-Allow-Origin'] = '*'
    else:
        response = make_response(jsonify({'success': False, 'msg': 'is not a valid user'}))
        response.headers['Access-Control-Allow-Origin'] = '*'

    return response


@app.route('/knx/available_labels.do', methods = ['GET'])
def available_labels():
    data = [
        '证券/股票/期货经纪人',
        '投资/理财顾问',
        '贷款/信贷专员',
        '保险/理赔管理',
        '股票/期货操盘手',
        '证券/股票/期货研究员',
        '客户/服务经理',
        '渠道/区域经理',
        '市场营销/策划',
        '市场推广/拓展',
        '销售/业务代表',
        '售后/客服/前台',
        '储备干部/管培生',
        '市场/行业/商业分析',
        '内容/产品运营',
        '产品/项目经理',
        '公关/外联',
        '人事/行政',
        '后勤/采购',
        '地产/置业顾问',
        '培训/咨询',
        'UI/UE/视觉设计',
        '数据分析/挖掘',
        '算法/机器学习/自然语言处理',
        '生物科技',
        '教务管理',
        '汽车/配件',
        '医药代表',
        '石油/化工/新能源',
        '测试工程师',
        '移动端开发',
        '后端开发',
        'web前端开发',
        '桌面/驱动开发',
        '小初高各科老师',
        '课程咨询/销售',
        '财务/会计/出纳',
        '风控/合规',
        '外语培训师',
        '税务/审计/核算',
        '临床/药理/病理研究',
        '法务/律师',
        '医师/药师',
        'IT运维',
        '游戏设计/策划',
        '助理/秘书'
    ]

    response = make_response(jsonify({'success': True, 'data': data}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    return response


@app.route('/knx/job_recommend.do', methods = ['GET'])
def job_recommend():
    """
    职位推荐接口
    :return:
    """
    UserKey = request.args.get('UserKey', '')
    UserID = request.args.get('UserID', '')

    user = User(UserID, UserKey)

    if not user:
        resp = {
            'success': False,
            'data': []
        }

        response = make_response(jsonify(resp))
        response.headers['Access-Control-Allow-Origin'] = '*'

        return response

    data = user.recommond_jobs(6)

    for job in data:
        job['id'] = str(job['_id'])

        if UserID != '0':
            job['isCollected'] = user.is_job_collected(job['platform'], job['id'])
            job['isDelivered'] = user.is_job_delivered(job['platform'], job['id'])

        append_logo_url(job)

        if '_id' in job:
            del job['_id']

    resp = {
        'success': True,
        'data': data
    }

    response = make_response(jsonify(resp))
    response.headers['Access-Control-Allow-Origin'] = '*'

    return response


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/company')
def company():
    return render_template('company.html')


@app.route('/jobs')
def jobs():
    return render_template('jobs.html')


# @app.route('/log')
# def log():
#     data = []
#
#     for log in user_log.find({}, {'_id': 0}):
#         item = {
#             'UserID': log['UserID'],
#             'UserKey': log['UserKey'],
#             'labels': log['labels'],
#             'job_queried': log['job_queried'],
#             'job_collected': [],
#             'job_viewed': [],
#             'job_delivered': [],
#             'evaluation': {
#                 'adaptation_index': {}
#             },
#             'resume': {
#                 'education': [],
#                 'internshipExperience': []
#             }
#         }
#
#         if 'evaluation' in log and 'adaptation_index' in log['evaluation']:
#             item['evaluation']['adaptation_index'] = log['evaluation']['adaptation_index']
#
#         if 'resume' in log and 'education' in log['resume']:
#             item['resume']['education'] = log['resume']['education']
#
#         if 'resume' in log and 'internshipExperience' in log['resume']:
#             item['resume']['internshipExperience'] = log['resume']['internshipExperience']
#
#         for i in log['job_collected']:
#             item['job_collected'].append(platform_posts.find_one({'_id': ObjectId(i['id'])})['name'])
#
#         for i in log['job_viewed']:
#             try:
#                 item['job_viewed'].append(platform_posts.find_one({'_id': ObjectId(i['id'])})['name'])
#             except:
#                 continue
#
#         for i in log['job_delivered']:
#             try:
#                 item['job_delivered'].append(platform_posts.find_one({'_id': ObjectId(i['id'])})['name'])
#             except:
#                 continue
#
#         data.append(item)
#
#     data.sort(key = lambda i: int(i['UserID']), reverse = True)
#
#     return render_template('user_log.html', title = '用户日志数据', logs = data)


# front = ['顾问', '咨询']
# middle = ['管理', '执行', '经理', '主管']
# back = ['工程师', '研究']


# def is_front(name):
#     for i in front:
#         if i in name:
#             return True
#
#     return False
#
#
# def is_middle(name):
#     for i in middle:
#         if i in name:
#             return True
#
#     return False
#
#
# def is_back(name):
#     for i in back:
#         if i in name:
#             return True
#
#     return False


# @app.route('/jobs_filter')
# def jobs_filter():
#     """
#     获取各个平台和官网的职位列表
#     :return:
#     """
#     industry = request.args.get('industry', '')
#     platform = request.args.get('platform', '')
#
#     start = int(request.args.get('start', 0))
#     count = int(request.args.get('count', 50))
#
#     # 平台职位查询
#     if platform != 'offical':
#         corps = client[platform + '_db'][platform + '_corps']
#
#         if cache.get('jobs_filter', str((platform, industry, start, count))):
#             data, total = cache.get('jobs_filter', str((platform, industry, start, count)))
#         else:
#             data = [item for item in platform_posts.find({
#                 'platform': platform,
#                 'subIndustry': industry,
#                 'exp': {
#                     '$size': 0
#                 },
#                 'description': {
#                     '$ne': ''
#                 }
#             }).skip(start).limit(count)]
#
#             total = platform_posts.find({
#                 'platform': platform,
#                 'subIndustry': industry,
#                 'exp': {
#                     '$size': 0
#                 },
#                 'description': {
#                     '$ne': ''
#                 }
#             }).count()
#
#             cache('jobs_filter', str((platform, industry, start, count)), (data, total))
#     else:
#         corps = None
#
#         if cache.get('jobs_filter', (platform, start, count)):
#             data, total = cache.get('jobs_filter', (platform, start, count))
#         else:
#             data = [item for item in offical_posts_coll.find({
#                 'exp': {
#                     '$size': 0
#                 },
#                 'description': {
#                     '$ne': ''
#                 }
#             }).skip(start).limit(count)]
#
#             total = offical_posts_coll.find({
#                 'exp': {
#                     '$size': 0
#                 },
#                 'description': {
#                     '$ne': ''
#                 }
#             }).count()
#
#             cache('jobs_filter', (platform, start, count), (data, total))
#
#     for item in data:
#         if corps:
#             c = corps.find_one({'name': item['company'].strip()})
#
#             if c:
#                 item['company_type'] = c['type']
#                 item['company_industry'] = c['industry']
#                 item['company_url'] = c['url']
#             else:
#                 item['company_type'] = ''
#                 item['company_industry'] = ''
#         else:
#             item['company_type'] = ''
#             item['company_industry'] = ''
#
#         if is_front(item['name']):
#             item['divide'] = 'f'
#         elif is_middle(item['name']):
#             item['divide'] = 'm'
#         elif is_back(item['name']):
#             item['divide'] = 'b'
#
#         if '_id' in item:
#             del item['_id']
#
#         if 'stime' in item:
#             del item['stime']
#
#     return json.dumps({
#         'success': True,
#         'data': data,
#         'total': total
#     })


# @app.route("/download_jobs", methods = ['GET'])
# def download_file():
#     platform = request.args.get('platform', '')
#
#     if os.path.exists('static/' + platform + ".csv"):
#         return send_from_directory('static', platform + ".csv", as_attachment = True)
#
#     datas = []
#
#     info = {
#         'f': '前台',
#         'm': '中台',
#         'b': '后台',
#         'empty': '暂无'
#     }
#
#     if platform == 'offical':
#         posts = offical_posts_coll
#     else:
#         posts = platform_posts
#
#     for item in posts.find({'platform': platform,
#                             'exp': {
#                                 '$size': 0
#                             },
#                             'description': {
#                                 '$ne': ''
#                             }
#                             }):
#         company, industry, name, description, divide = item['company'], item['industry'], item['name'], item['description'], item['divide'] if 'divide' in item else 'empty'
#         datas.append([company, industry, name, description, info[divide]])
#
#     df = pd.DataFrame(datas)
#     df.to_csv('static/' + platform + ".csv", encoding = "utf_8_sig")
#
#     time.sleep(1)
#
#     return send_from_directory('static', platform + ".csv", as_attachment = True)


@app.route('/job_count')
def job_count():
    platforms = ['dajie', 'qiancheng', 'yingcai', 'zhilian']

    data = {}

    for plt in platforms:
        data[plt] = {
            'posts': platform_posts.find({
                'platform': plt,
                'exp': {
                    '$size': 0
                },
                'description': {
                    '$ne': ''
                }
            }).count()
        }

    data['offical'] = {
        'posts': offical_posts_coll.find({
            'exp': {
                '$size': 0
            },
            'description': {
                '$ne': ''
            }
        }).count()
    }

    return json.dumps({
        'success': True,
        'data': data
    })


@app.route('/knx/get_user_log.do')
def get_user_log():
    """
    获取用户日志
    :return:
    """
    data = [item for item in user_log.find({}, {'_id': 0})]

    return json.dumps({
        'success': True,
        'data': data
    })


@app.route('/knx/positionNameList.do', methods = ['POST', 'GET'])
def positionNameList():
    freq_high_jobs = [
        ('会计', 3137),
        ('销售代表', 2969),
        ('出纳', 1702),
        ('销售经理', 1394),
        ('客户经理', 1222),
        ('财务经理', 1157),
        ('客服专员', 934),
        ('法务专员', 769),
        ('产品经理', 745),
        ('人事专员', 643),
        ('市场专员', 598),
        ('课程顾问', 578),
        ('财务助理', 566),
        ('Java开发工程师', 542),
        ('证券经纪人', 478),
        ('销售顾问', 477),
        ('投资顾问', 429),
        ('财务总监', 364),
        ('销售总监', 363),
        ('储备干部', 360),
        ('文案策划', 354),
        ('理财顾问', 348),
        ('行政前台', 301),
        ('法务主管', 293),
        ('总经理助理', 292),
        ('前端开发工程师', 284),
        ('行政助理', 280),
        ('平面设计', 270),
        ('JAVA开发工程师', 261),
        ('软件工程师', 259),
        ('外贸业务员', 255),
        ('Android开发工程师', 254)
    ]

    data = {
        'success': True,
        'data': [item[0] for item in freq_high_jobs]
    }

    response = make_response(jsonify(data))
    response.headers['Access-Control-Allow-Origin'] = '*'

    return response


plts_map = {
    'qiancheng': [],
    'dajie': [],
    'zhilian': []
}


# for item in qiancheng_corps.find({
#     'not_wanted': {
#         '$exists': False
#     }
# }, {'description': 0, '_id': 0}):
#     plts_map['qiancheng'].append(item)
#
# for item in dajie_corps.find({
#     'not_wanted': {
#         '$exists': False
#     }
# }, {'description': 0, '_id': 0}):
#     plts_map['dajie'].append(item)
#
# for item in zhilian_corps.find({
#     'not_wanted': {
#         '$exists': False
#     }
# }, {'description': 0, '_id': 0}):
#     plts_map['zhilian'].append(item)


@app.route('/knx/get_enterprise_list')
def get_enterprise_list():
    page = int(request.args.get('page', 1)) - 1
    platform = request.args.get('platform', '').strip()

    data = []

    for item in plts_map[platform][page * 50:]:
        data.append(item)

        if len(data) == 50:
            break

    return json.dumps({
        'success': True,
        'data': data,
        'length': len(plts_map[platform])
    })


@app.route('/knx/import_enterprise.do', methods = ['POST'])
def import_enterprise():
    item = json.loads(request.form.get('JsonData'))

    for field in ['name', 'logoUrl', 'compId', 'industry', 'location']:
        if not field in item or not item[field]:
            response = make_response(jsonify({'success': False, 'msg': field + ' is empty'}))
            response.headers['Access-Control-Allow-Origin'] = '*'
            return response

    item['platform'] = 'knx'
    item['type'] = item['type'] if 'type' in item else ''
    item['site'] = item['site'] if 'site' in item else ''
    item['size'] = item['size'] if 'size' in item else ''
    item['description'] = item['description'] if 'description' in item else ''
    item['stime'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    knx_custom_enterprise.replace_one({'compId': item['compId']}, item, True)

    response = make_response(jsonify({'success': True, 'msg': 'successfully insert one!'}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    return response


@app.route('/knx/import_position.do', methods = ['POST'])
def import_position():
    """
    导入自定义职位
    :return:
    """
    item = json.loads(request.form.get('JsonData'))

    for field in ['title', 'type', 'nature', 'location', 'date', 'compId', 'requirement', 'description', 'jid']:
        if not field in item or not item[field]:
            response = make_response(jsonify({'success': False, 'msg': field + ' is empty'}))
            response.headers['Access-Control-Allow-Origin'] = '*'
            return response

    item['platform'] = 'knx'
    item['edu'] = item['edu'] if 'edu' in item else ''
    item['exp'] = item['exp'] if 'exp' in item else ''
    item['welfare'] = item['welfare'] if 'welfare' in item else ''

    item['name'] = item['title']
    item['priority'] = 20
    item['exp'] = item['exp'].split(',')
    item['salary'] = item['salary'].split(',')
    item['welfare'] = item['welfare'].split(',')
    item['stime'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    comp = knx_custom_enterprise.find_one({'compId': item['compId']})

    if comp:
        item['company'] = comp['name']
    else:
        item['company'] = ''

    knx_custom_position.replace_one({'jid': item['jid']}, item, True)

    response = make_response(jsonify({'success': True, 'msg': 'successfully insert one!'}))
    response.headers['Access-Control-Allow-Origin'] = '*'

    return response


@app.route('/knx/del_position.do', methods = ['GET'])
def del_position():
    """
    删除自导入职位
    :return:
    """
    jid = request.args.get('jid', '')

    if not jid:
        response = make_response(jsonify({'success': False, 'msg': 'jid is empty'}))
        response.headers['Access-Control-Allow-Origin'] = '*'
        return response

    if knx_custom_position.find_one({'jid': jid}):
        knx_custom_position.delete_one({'jid': jid})

        response = make_response(jsonify({'success': True, 'msg': 'delete successfully'}))
        response.headers['Access-Control-Allow-Origin'] = '*'
        return response

    response = make_response(jsonify({'success': False, 'msg': 'can not find this jd,please check it'}))
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response


with app.test_request_context():
    url_for('static', filename = '*')

if __name__ == '__main__':
    if 'debug' in sys.argv:
        app.debug = True

    # app.run(host = '0.0.0.0', port = 8085, threaded = True)
    WSGIServer(('0.0.0.0', 8085), app).serve_forever()
